# Find arpackng (arpack-ng), prefer CMake config, fallback to pkg-config if not found

# Try to find arpack-ng using pkg-config only if config files were not found
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
    pkg_check_modules(PC_arpackng QUIET arpack)
    if(PC_arpackng_FOUND)
        set(arpackng_FOUND TRUE)
        set(arpackng_DIR ${PC_arpackng_PREFIX})
        set(arpackng_INCLUDE_DIRS ${PC_arpackng_INCLUDE_DIRS})
        set(arpackng_LIBRARIES ${PC_arpackng_LIBRARIES})
        set(arpackng_DEFINITIONS ${PC_arpackng_CFLAGS_OTHER})
    else()
        set(arpackng_FOUND FALSE)
    endif()
else()
    set(arpackng_FOUND FALSE)
endif()
message(STATUS "Found arpack-ng via pkg-config: ${arpackng_FOUND}")
# Provide standard find_package variables
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(arpackng DEFAULT_MSG arpackng_LIBRARIES arpackng_INCLUDE_DIRS)

mark_as_advanced(arpackng_INCLUDE_DIRS arpackng_LIBRARIES arpackng_DEFINITIONS arpackng_DIR)